package com.wannengbang.storemobile.homepage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wannengbang.storemobile.R;
import com.wannengbang.storemobile.bean.EBankIndustryListBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 消息列表
 */
public class ChooseIndustryListAdapter extends RecyclerView.Adapter<ChooseIndustryListAdapter.ViewHolder> {

    private List<EBankIndustryListBean.DataBean> listsBeans;
    private Context context;
    private onCallBackListener onCallBackListener;

    public ChooseIndustryListAdapter(List<EBankIndustryListBean.DataBean> listsBeans) {
        this.listsBeans = listsBeans;
    }

    public void setOnCallBackListener(ChooseIndustryListAdapter.onCallBackListener onCallBackListener) {
        this.onCallBackListener = onCallBackListener;
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_choose_industry, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        EBankIndustryListBean.DataBean dataBean = listsBeans.get(position);
        holder.tvName.setText("(" + dataBean.getCode() + ")" + dataBean.getText());
        holder.itemView.setOnClickListener(v -> {
            onCallBackListener.onCallBack(position);
        });
    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_name)
        TextView tvName;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface onCallBackListener {
        void onCallBack(int position);
    }
}
